{{include file = "layouts/header.tpl"}}

<script type="text/javascript"
	src="{{$smarty.const.WEBSITE_URL}}public/assets/lib/ajaxupload.js"></script>

<script type="text/javascript">
  var weburl = '{{$smarty.const.WEBSITE_URL}}';
  getUsermassage();


	//文件上传组件处理
	jQuery(function () {
		 	var button = jQuery('#selectfile');//绑定事件
		var load = new AjaxUpload(button, {//绑定AjaxUpload
	    action: "{{$smarty.const.WEBSITE_URL}}admin/fileupload/fileup",//文件要上传到的处理页面,语言可以PHP,ASP,JSP等
	    type:"POST",//提交方式
	    data:{//还可以提交的值
	        module:"ajaxupload",
	        type:jQuery("#__mstype__").attr("value"),
	    },
	    autoSubmit:true,//选择文件后,是否自动提交.这里可以变成true,自己去看看效果吧.
	    name:'msUploadFile',//提交的名字
	    onChange:function(file,ext){//当选择文件后执行的方法,ext存在文件后续,可以在这里判断文件格式
// 			$("#user_photo").attr("value",file);
	    },
	    onSubmit: function (file, ext) {//提交文件时执行的方法
	    	if(ext && /^(jpg|jpeg|png|gif)$/.test(ext)){
				//ext是后缀名
	    		button.value = "正在上传…";
	    		button.disabled = "disabled";
			}else{	
				alert("不支持的文件格式！只能上传jpg|jpeg|png|gif") ;
				return false;
			}
	    },
	    onComplete: function (file, response) {//文件提交完成后可执行的方法
	        button.text('浏览');
	        this.enable();
			var data=eval("("+response+")");
			if(data.type==0){
				alert(data.message);
			}else{
				$('#user_photo').val(data.filename);
				$("#user_img").attr("src","{{$smarty.const.WEBSITE_URL}}upload/"+data.filename);
	        	
			}
	    }
	});
	});
	
  
function getUsermassage(){
	$.ajax({
        type: "POST",
        url: weburl+'usermanage/getMsg',
        success:function(data){
        	var udata =   JSON.parse(data);
        	console.log(udata,'%');
        	$("#userid").val(udata.userid);
        	$("#username").val(udata.username);
        	$("#firstname").val(udata.firstname);
        	$("#lastname").val(udata.lastname);
        	$("#email").val(udata.email);
        	$("#user_photo").val(udata.user_photo);
        	$("#password").val(udata.password);

        	$("#user_img").attr("src","{{$smarty.const.WEBSITE_URL}}upload/"+udata.user_photo);
        	
	    },
        error: function () {
        }
    });
}
function modify(){
	$.ajax({
		type:"post",
        url: weburl+'usermanage/modify',
        data:$('#loadform').serialize(),
        success:function(data){
            if(data >0){
                alert("修改成功!");
            }
	    },
        error: function () {
        }
    });
}

function changePhoto(){
	
}
</script>

<div class="container-fluid">
	<div class="row-fluid">
		<table style="width: 800; height: 400px">
			<tr>
				<td>
					<form id="loadform" method="post" class="form-horizontal"
						style="width: 200px">
						<input type="text" id="user_photo" name="user_photo"
								  hidden="true" />
						<div class="control-group" hidden="true">
							<input type="text" id="userid" name="userid"
								value="{{$user.userid}}" hidden="true" />
						</div>
						<div class="control-group">
							<label class="control-label" for="Text input">用户名:</label>
							<div class="controls">
								<input id="username" placeholder="用户名" name="username"> </input>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="Text input">姓:</label>
							<div class="controls">
								<input id="firstname" placeholder="姓" name="firstname"> </input>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="Text input">名:</label>
							<div class="controls">
								<input id="lastname" placeholder="名字" name="lastname"> </input>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="Text input">邮箱:</label>
							<div class="controls">
								<input id="email" placeholder="邮箱" name="email"> </input>
							</div>
						</div>

						<div class="control-group">
							<label class="control-label" for="Text input">密码</label>
							<div class="controls">
								<input id="password" type="password" placeholder="密码"
									name="password"> </input>
							</div>
						</div>

						<div class="control-group">
							<button type="button" class="btn btn-primary" onclick="modify()">修改</button>
						</div>
					</form>
				</td>
				<td><img id="user_img" alt=""
					src="{{$smarty.const.WEBSITE_URL}}public/photo/3.jpg" width="100"
					height="100" /> <input type="button" class="btn btn-small"
					id="selectfile" value="图片选择" /></td>
			</tr>
		</table>
	</div>
</div>
{{include file = "layouts/footer.tpl"}}
